/**
 * LabelTextId
 * a57633056a
 * Fri Aug 19 2022 15:40:18 GMT+0800 (中国标准时间)
 * StringId.ts
 * LabelTextId
 * db://assets/script/framework/components/label/StringId.ts
 * https://docs.cocos.com/creator/3.6/manual/zh/
 */
import { Component, Label, RichText, _decorator } from 'cc';
import StringUtils from '../../utils/StringUtils';
const { ccclass, property, menu } = _decorator;

@ccclass('LabelTextId')
@menu('扩展组件/LabelTextId')
export class LabelTextId extends Component {
    @property({ tooltip: "模版Id" })
    textId: string = "";

    private text: Label | RichText = null;
    private params?: { [key: string]: string | number } = null;
    onLoad() {
        this.text = this.node.getComponent(Label) || this.node.getComponent(RichText);
        this.updateText(this.textId);
    }
    start() {
    }

    updateText(textId: string, params?: { [key: string]: string | number }) {
        if (!this.text || !textId) {
            return;
        }
        this.textId = textId;
        this.params = params;
        this.text.string = StringUtils.getStr(this.textId, this.params);
    }
}